<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>前端监控SDK</title>
</head>

<body>
    <div id="container">
        <div class="content" style="width:600px;word-wrap:break-word;">
            <!-- <input type="button" value="点击抛出错误" onclick="btnClick()" />
            <input type="button" value="点击抛出promise错误" onclick="btnPromiseClick()" />
            <input type="button" value="发起ajax成功请求" onclick="sendAjaxSuccess()" />
            <input type="button" value="发起ajax失败请求" onclick="sendAjaxError()" /> -->
        </div>
    </div>
    
    <script>
        

        function btnClick(){
            window.someVariable.error = 'someVariable';
        }
        function btnPromiseClick() {
            new Promise(function (resolve, reject) {
                window.someVar.error = 'error';
                // reject('error')
            }).then(res=>{
                console.log(res)
            });
        }

        function sendAjaxSuccess() {
            let xhr = new XMLHttpRequest;
            xhr.open('GET','/success',true)
            xhr.responseType = 'json'
            xhr.onload = function () {
                console.log(xhr.response);
            }
            xhr.send();
        }
        function sendAjaxError() {
            let xhr = new XMLHttpRequest;
            xhr.open('POST', '/error', true);
            xhr.responseType = 'json';
            xhr.onload = function () {
                console.log(xhr.response);
            }
            xhr.onerror = function (error) {
                console.log(error);
            }
            xhr.send("name=ikki");
        }
        
        // let content = document.getElementsByClassName('content')[0];
        // content.innerHTML = '<span>@</span>'.repeat(1000);

        // dom解析完成，即使依赖的资源没有加载完成，也会触发这个事件
        // document.addEventListener('DOMContentLoaded', function () {
        //     let start = Date.now();
        //     while ((Date.now() - start) < 1000) {}
        // });


        let content = document.getElementsByClassName('content')[0];
        setTimeout(() => {
            let h1 = document.createElement('h1');
            h1.innerHTML = '我是最有重要的内容';
            h1.setAttribute('elementtiming', 'meaningful');
            content.appendChild(h1);
        }, 2000);
    </script>
    <!-- <script src="./error.js"></script> -->
</body>
</html>